﻿function BaseClassVm(jsonOfObject, mapping) {
    var base = this;

    base.OriginalJsonOfObject = jsonOfObject;
    base.Mapping = mapping;
    base.DirtyFlag = ko.dirtyFlag(base, false);

    base.IsDirty = ko.computed(function() {
        return base.DirtyFlag.isDirty();
    });

    base.Refresh = function(jsonData) {
        ko.mapping.fromJS(jsonData, base.Mapping, base);
    };

    base.Reset = function() {
        ko.mapping.fromJS(base.OriginalJsonOfObject, base.Mapping);
    };

    base.Clone = function () {
        var clonedObject = new BaseClassVm(base.OriginalJsonOfObject, {});
        return clonedObject;
    };

    base.Refresh(jsonOfObject, mapping);
}
